﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlConnect
{
    internal class DbFactory
    {
        private static string _assemblyName = "SqlConnect"; // 默认程序集名称

        public static DbCommand CreateCommand(string dbType)
        {
            string commandClassName = $"{dbType}Command";
            Type commandType = Type.GetType($"{_assemblyName}.{commandClassName}");
            return (DbCommand)Activator.CreateInstance(commandType);
        }

        public static DbConnection CreateConnection(string dbType)
        {
            string connectionClassName = $"{dbType}Connection";
            Type connectionType = Type.GetType($"{_assemblyName}.{connectionClassName}");

            if (connectionType == null)
            {
                throw new ArgumentException($"Database connection type '{dbType}' not found.");
            }

            return (DbConnection)Activator.CreateInstance(connectionType);
        }

    }
}
